{extend name="public/base" /}
{block name="style"}
<style>
 .uploadimage {
     width:200px;
     height:200px
 }
</style>
{/block}
{block name="button"}
       <a data-modal='{:url("add")}'  class='layui-btn layui-btn-sm layui-btn-primary'>添加</a>
{/block}
{block name="content"}
        <form class="layui-form layui-form-pane form-search" action="{:url()}" onsubmit="return false" method="post" autocomplete="off">
            <div class="layui-form-item layui-inline">
                <label class="layui-form-label">状态</label>
                <div class="layui-input-inline">
                    <select name="pay_status" lay-search class="layui-select">
                        <option value='0'>全部</option>
                        <option value='1'>启用</option>
                        <option value='-1'>禁用</option>
                    </select>
                </div>
            </div>
            <div class="layui-form-item layui-inline">
                <button class="layui-btn layui-btn-primary"><i class="layui-icon">&#xe615;</i>搜索</button>
            </div>
        </form>
        <table id="ThumbTable"  data-url="{:url('index')}" data-target-search="form.form-search"></table>
{/block}
{block name='script'}
<script>
    $(function () {
        $.menu.highlight_subnav("{:url('index')}")
        $('#ThumbTable').layTable({
            even: true,
            height: 'full',
            method: 'post',
            sort: {field: 'sort', type: 'asc'},
            url: "{:url('index')}" ,
            page: true,
            cols: [[
                {checkbox: true, fixed: true},
                {field: 'id', title: 'id', width: 30, align: 'center'},
                {field: 'status', title: '状态', align: 'left', width: 120, templet: '#StatusSwitchTpl'},
                {field: 'remark', title: '备注', width: 140, align: 'center'},
                {
                    field: 'thumb', title: 'thumb', width: 120, align: 'center', templet: function (d) {
                        if (!d.thumb) return '-';
                        return layui.laytpl('<div class="headimg headimg-ss shadow-inset margin-0" data-tips-image data-tips-hover data-lazy-src="{{d.thumb}}"></div>').render(d);
                    }
                },
                {field: 'link_url', title: '链接地址', width: 250, align: 'left'},
                {field: 'sort', title: '排序', align: 'center',  sort: true},
                {field: 'create_at', title: '创建', align: 'center', sort: true},
                {field: 'update_at', title: '更新时间', align: 'center', sort: true},
                {field: 'create_operator', title: '创建人账户', align: 'left'},
                {field: 'update_operator', title: '更新人账户', align: 'left', minWidth: 170},
                {toolbar: '#toolbar', title: '操作面板', align: 'center', fixed: 'right'}
            ]]
        });
        // 数据状态切换操作
        layui.form.on('switch(StatusSwitch)', function (obj) {
            var data = {id: obj.value, status: obj.elem.checked > 0 ? 1 : -1};
            $.form.load("{:url('setStatus')}", data, 'post', function (ret) {
                if (ret.code >1) $.msg.error(ret.msg, 3, function () {
                    $('#ThumbTable').trigger('reload');
                }); else {
                    $('#ThumbTable').trigger('reload')
                }
                return false;
            }, false);
        });
    });
</script>
<!-- 数据状态切换模板 -->
<script type="text/html" id="StatusSwitchTpl">
    <input type="checkbox" value="{{d.id}}" lay-skin="switch" lay-text="上架|下架" lay-filter="StatusSwitch" {{-d.status==1?'checked':''}}>
    {{-d.status==1 ? '<b class="color-green">上架</b>' : '<b class="color-red">下架</b>'}}
</script>
<script type="text/html" id="toolbar">
    <a class="layui-btn layui-btn-sm"  data-title="编辑用户" data-modal='{:url("edit")}?id={{d.id}}'>编辑</a>
</script>
{/block}
